home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_automake.idb / usr / freeware / bin / aclocal.z / aclocal
Encoding:
Text File  |  1999-07-16  |  10.0 KB  |  427 lines

  1. #!/usr/freeware/bin/perl
  2. # -*- perl -*-
  3. # Generated automatically from aclocal.in by configure.
  4.  
  5. # aclocal - create aclocal.m4 by scanning configure.in
  6. # Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
  7.  
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12.  
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17.  
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. # 02111-1307, USA.
  22.  
  23. # Written by Tom Tromey <tromey@cygnus.com>.
  24.  
  25. eval 'exec /usr/freeware/bin/perl -S $0 ${1+"$@"}'
  26.     if 0;
  27.  
  28. # aclocal - scan configure.in and generate aclocal.m4.
  29.  
  30. # Some constants.
  31. $VERSION = "1.4";
  32. $PACKAGE = "automake";
  33. $prefix = "/usr/freeware";
  34. # Note that this isn't pkgdatadir, but a separate directory.
  35. $acdir = "${prefix}/share/aclocal";
  36.  
  37. # Some globals.
  38.  
  39. # Exit status.
  40. $exit_status = 0;
  41.  
  42. # Text to output.
  43. $output = '';
  44.  
  45. # Output file name.
  46. $output_file = 'aclocal.m4';
  47.  
  48. # Which macros have been seen.
  49. %macro_seen = ();
  50.  
  51. # Which files have been seen.
  52. %file_seen = ();
  53.  
  54. # Map macro names to file names.
  55. %map = ();
  56.  
  57. # Map file names to file contents.
  58. %file_contents = ();
  59.  
  60. # How much to say.
  61. $verbosity = 0;
  62.  
  63. @obsolete_macros =
  64.     (
  65.      'AC_FEATURE_CTYPE',
  66.      'AC_FEATURE_ERRNO',
  67.      'AC_FEATURE_EXIT',
  68.      'AC_SYSTEM_HEADER',
  69.      'fp_C_PROTOTYPES',
  70.      'fp_FUNC_FNMATCH',
  71.      'fp_PROG_CC_STDC',
  72.      'fp_PROG_INSTALL',
  73.      'fp_WITH_DMALLOC',
  74.      'fp_WITH_REGEX',
  75.      'gm_PROG_LIBTOOL',
  76.      'jm_MAINTAINER_MODE',
  77.      'md_TYPE_PTRDIFF_T',
  78.      'ud_PATH_LISPDIR',
  79.      'ud_GNU_GETTEXT',
  80.  
  81.      # Now part of autoconf proper, under a different name.
  82.      'AM_FUNC_FNMATCH',
  83.      'AM_SANITY_CHECK_CC',
  84.      'AM_PROG_INSTALL',
  85.      'AM_EXEEXT',
  86.      'AM_CYGWIN32',
  87.      'AM_MINGW32',
  88.  
  89. # These aren't quite obsolete.
  90. #      'md_PATH_PROG',
  91. #      'ud_LC_MESSAGES',
  92. #      'ud_WITH_NLS'
  93.      );
  94.  
  95. $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
  96.  
  97. # Matches a macro definition.
  98. $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
  99.  
  100. # Matches an AC_REQUIRE line.
  101. $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
  102.  
  103.  
  104.  
  105. local (@dirlist) = &parse_arguments (@ARGV);
  106. &scan_m4_files ($acdir, @dirlist);
  107. &scan_configure;
  108. if (! $exit_status)
  109. {
  110.     &write_aclocal;
  111. }
  112. &check_acinclude;
  113.  
  114. exit $exit_status;
  115.  
  116. ################################################################
  117.  
  118. # Print usage and exit.
  119. sub usage
  120. {
  121.     local ($status) = @_;
  122.  
  123.     print "Usage: aclocal [OPTIONS] ...\n\n";
  124.     print "Generate aclocal.m4 by scanning configure.in\n
  125.   --acdir=DIR           directory holding config files
  126.   --help                print this help, then exit
  127.   -I DIR                add directory to search list for .m4 files
  128.   --output=FILE         put output in FILE (default aclocal.m4)
  129.   --print-ac-dir        print name of directory holding m4 files
  130.   --verbose             don't be silent
  131.   --version             print version number, then exit
  132.  
  133. Report bugs to <bug-automake\@gnu.org>.\n";
  134.  
  135.     exit $status;
  136. }
  137.  
  138. # Parse command line.
  139. sub parse_arguments
  140. {
  141.     local (@arglist) = @_;
  142.     local (@dirlist);
  143.     local ($print_and_exit) = 0;
  144.  
  145.     while (@arglist)
  146.     {
  147.     if ($arglist[0] =~ /^--acdir=(.+)$/)
  148.     {
  149.         $acdir = $1;
  150.     }
  151.     elsif ($arglist[0] =~/^--output=(.+)$/)
  152.     {
  153.         $output_file = $1;
  154.     }
  155.     elsif ($arglist[0] eq '-I')
  156.     {
  157.         shift (@arglist);
  158.         push (@dirlist, $arglist[0]);
  159.     }
  160.     elsif ($arglist[0] eq '--print-ac-dir')
  161.     {
  162.         $print_and_exit = 1;
  163.     }
  164.     elsif ($arglist[0] eq '--verbose')
  165.     {
  166.         ++$verbosity;
  167.     }
  168.     elsif ($arglist[0] eq '--version')
  169.     {
  170.         print "aclocal (GNU $PACKAGE) $VERSION\n\n";
  171.         print "Copyright (C) 1999 Free Software Foundation, Inc.\n";
  172.         print "This is free software; see the source for copying conditions.  There is NO\n";
  173.         print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
  174.         print "Written by Tom Tromey <tromey\@cygnus.com>\n";
  175.         exit 0;
  176.     }
  177.     elsif ($arglist[0] eq '--help')
  178.     {
  179.         &usage (0);
  180.     }
  181.     else
  182.     {
  183.         die "aclocal: unrecognized option -- \`$arglist[0]'\nTry \`aclocal --help' for more information.\n";
  184.     }
  185.  
  186.     shift (@arglist);
  187.     }
  188.  
  189.     if ($print_and_exit)
  190.     {
  191.     print $acdir, "\n";
  192.     exit 0;
  193.     }
  194.  
  195.     return @dirlist;
  196. }
  197.  
  198. ################################################################
  199.  
  200. sub scan_configure
  201. {
  202.     open (CONFIGURE, "configure.in")
  203.     || die "aclocal: couldn't open \`configure.in': $!\n";
  204.  
  205.     # Make sure we include acinclude.m4 if it exists.
  206.     if (-f 'acinclude.m4')
  207.     {
  208.     &add_file ('acinclude.m4');
  209.     }
  210.  
  211.     while (<CONFIGURE>)
  212.     {
  213.     # Remove comments from current line.
  214.     s/\bdnl\b.*$//;
  215.     s/\#.*$//;
  216.  
  217.     if (/$obsolete_rx/o)
  218.     {
  219.         chop;
  220.         warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
  221.         $exit_status = 1;
  222.         next;
  223.     }
  224.  
  225.     # Search for things we know about.  The "search" sub is
  226.     # constructed dynamically by scan_m4_files.
  227.     if (! &search && /(^|\s+)(AM_[A-Z_]+)/)
  228.     {
  229.         # Macro not found, but AM_ prefix found.
  230.         warn "aclocal: configure.in: $.: macro \`$2' not found in library\n";
  231.         $exit_status = 1;
  232.     }
  233.     }
  234.  
  235.     close (CONFIGURE);
  236. }
  237.  
  238. ################################################################
  239.  
  240. # Check macros in acinclude.m4.  If one is not used, warn.
  241. sub check_acinclude
  242. {
  243.     local ($key);
  244.  
  245.     foreach $key (keys %map)
  246.     {
  247.     next unless $map{$key} eq 'acinclude.m4';
  248.     if (! $macro_seen{$key})
  249.     {
  250.         # FIXME: should print line number of acinclude.m4.
  251.         warn "aclocal: macro \`$key' defined in acinclude.m4 but never used\n";
  252.     }
  253.     }
  254. }
  255.  
  256. ################################################################
  257.  
  258. # Scan all the installed m4 files and construct a map.
  259. sub scan_m4_files
  260. {
  261.     local (@dirlist) = @_;
  262.  
  263.     # First, scan acinclude.m4 if it exists.
  264.     if (-f 'acinclude.m4')
  265.     {
  266.     $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
  267.     }
  268.  
  269.     local ($m4dir);
  270.     foreach $m4dir (@dirlist)
  271.     {
  272.     opendir (DIR, $m4dir)
  273.         || die "aclocal: couldn't open directory \`$m4dir': $!\n";
  274.     local ($file, $fullfile, $expr);
  275.     foreach $file (sort grep (! /^\./, readdir (DIR)))
  276.     {
  277.         # Only examine .m4 files.
  278.         next unless $file =~ /\.m4$/;
  279.  
  280.         # Skip some files when running out of srcdir.
  281.         next if $file eq 'aclocal.m4';
  282.  
  283.         $fullfile = $m4dir . '/' . $file;
  284.         $file_contents{$fullfile} = &scan_file ($fullfile);
  285.     }
  286.     closedir (DIR);
  287.     }
  288.  
  289.     # Construct a new function that does the searching.  We use a
  290.     # function (instead of just evalling $search in the loop) so that
  291.     # "die" is correctly and easily propagated if run.
  292.     local ($search, $expr, $key) = '';
  293.     foreach $key (reverse sort keys %map)
  294.     {
  295.     # EXPR is a regexp matching the name of the macro.
  296.     ($expr = $key) =~ s/(\W)/\\$1/g;
  297.     $search .= ("if (/" . $expr . "/) { & add_macro (" . $key
  298.             . "); return 1; }\n");
  299.     }
  300.     $search .= "return 0;\n";
  301.     eval 'sub search { ' . $search . '};';
  302.     die "internal error: $@\n search is $search " if $@;
  303. }
  304.  
  305. ################################################################
  306.  
  307. # Add a macro to the output.
  308. sub add_macro
  309. {
  310.     local ($macro) = @_;
  311.  
  312.     # We want to ignore AC_ macros.  However, if an AC_ macro is
  313.     # defined in (eg) acinclude.m4, then we want to make sure we mark
  314.     # it as seen.
  315.     return if $macro =~ /^AC_/ && ! defined $map{$macro};
  316.  
  317.     if (! defined $map{$macro})
  318.     {
  319.     warn "aclocal: macro \`$macro' required but not defined\n";
  320.     $exit_status = 1;
  321.     return;
  322.     }
  323.  
  324.     print STDERR "saw macro $macro\n" if $verbosity;
  325.     $macro_seen{$macro} = 1;
  326.     &add_file ($map{$macro});
  327. }
  328.  
  329. # Add a file to output.
  330. sub add_file
  331. {
  332.     local ($file) = @_;
  333.  
  334.     # Only add a file once.
  335.     return if ($file_seen{$file});
  336.     $file_seen{$file} = 1;
  337.  
  338.     $output .= $file_contents{$file} . "\n";
  339.     local ($a, @rlist);
  340.     foreach (split ("\n", $file_contents{$file}))
  341.     {
  342.     # This is a hack for Perl 4.
  343.     $a = $_;
  344.     if ($a =~ /$ac_require_rx/g)
  345.     {
  346.         push (@rlist, $1);
  347.     }
  348.  
  349.     # This function constructed dynamically.
  350.     if (! &search && /(^|\s+)(AM_[A-Z_]+)/)
  351.     {
  352.         # Macro not found, but AM_ prefix found.
  353.         warn "aclocal: configure.in: $.: macro \`$2' not found in library\n";
  354.         $exit_status = 1;
  355.     }
  356.     }
  357.  
  358.     local ($macro);
  359.     foreach $macro (@rlist)
  360.     {
  361.     &add_macro ($macro);
  362.     }
  363. }
  364.  
  365. # Scan a single M4 file.  Return contents.
  366. sub scan_file
  367. {
  368.     local ($file) = @_;
  369.  
  370.     open (FILE, $file)
  371.     || die "aclocal: couldn't open \`$file': $!\n";
  372.     local ($contents) = '';
  373.     while (<FILE>)
  374.     {
  375.     # Ignore `##' lines.
  376.     next if /^##/;
  377.  
  378.     $contents .= $_;
  379.  
  380.     if (/$ac_defun_rx/)
  381.     {
  382.         if (!defined $map{$1})
  383.         {
  384.         $map{$1} = $file;
  385.         }
  386.         # Allow acinclude.m4 to override other macro files.
  387.         elsif ($map{$1} ne 'acinclude.m4' || $file eq 'acinclude.m4')
  388.         {
  389.         warn "aclocal: $file: $.: duplicated macro \`$1'\n";
  390.         $exit_status = 1;
  391.         }
  392.         print STDERR "Found macro $1 in $file: $.\n" if $verbosity;
  393.     }
  394.     }
  395.     close (FILE);
  396.  
  397.     return $contents;
  398. }
  399.  
  400. ################################################################
  401.  
  402. # Write output.
  403. sub write_aclocal
  404. {
  405.     return if ! length ($output);
  406.  
  407.     print STDERR "Writing $output_file\n" if $verbosity;
  408.  
  409.     open (ACLOCAL, "> " . $output_file)
  410.     || die "aclocal: couldn't open \`$output_file' for writing: $!\n";
  411.     print ACLOCAL "dnl $output_file generated automatically by aclocal $VERSION\n";
  412.     print ACLOCAL "\
  413. dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
  414. dnl This file is free software; the Free Software Foundation
  415. dnl gives unlimited permission to copy and/or distribute it,
  416. dnl with or without modifications, as long as this notice is preserved.
  417.  
  418. dnl This program is distributed in the hope that it will be useful,
  419. dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  420. dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  421. dnl PARTICULAR PURPOSE.
  422.  
  423. ";
  424.     print ACLOCAL $output;
  425.     close (ACLOCAL);
  426. }
  427.